<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>

    var arr = [3, 1, 2, 9, 5, 6, 7, 8, 10]

    var length = arr.length
    for (var i = 0; i < length; i++) {
      for (var j = i + 1; j < length; j++) {
        if (arr[i] > arr[j]) {
          var flag = arr[i]
          arr[i] = arr[j]
          arr[j] = flag
        }
      }
    }
    console.log(arr)
  </script>
</body>

</html>